﻿Imports System.IO

Partial Class companyevents
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Load Title
        Try
            Using sr As New StreamReader("D:\Information_Management\WebSite2\albums\" & Request.QueryString("album") & "\title.txt")
                Dim line As String
                line = sr.ReadToEnd()
                'Console.WriteLine(line)
                lblTitle.Text = line
            End Using
        Catch ex As Exception
            'Console.WriteLine("The file could not be read:")
            'Console.WriteLine(ex.Message)
        End Try

        'Load Description
        Try
            Using sr As New StreamReader("D:\Information_Management\WebSite2\albums\" & Request.QueryString("album") & "\description.txt")
                Dim line As String
                line = sr.ReadToEnd()
                'Console.WriteLine(line)
                lblDesc.Text = line
            End Using
        Catch ex As Exception
            'Console.WriteLine("The file could not be read:")
            'Console.WriteLine(ex.Message)
        End Try


    End Sub
    Dim appPath As String = HttpContext.Current.Request.PhysicalApplicationPath
    Protected Sub Page_LoadComplete(sender As Object, e As EventArgs) Handles Me.LoadComplete
        Try
            If Page.IsPostBack = False Then
                Repeater1.DataSource = GetPhotos()
                Repeater1.DataBind()
            End If
        Catch ex As Exception
            Response.Write("Album Not Found")

        End Try
    End Sub
    Function GetPhotos() As ArrayList
        Dim returnList As New ArrayList

        Dim diFiles As DirectoryInfo = New DirectoryInfo("D:\Information_Management\WebSite2\albums\" & Request.QueryString("album") & "\")

        For Each File As FileInfo In diFiles.GetFiles("*.jpg")
            returnList.Add(Page.ResolveUrl("~/") & "albums/" & Request.QueryString("album") & "/" & Path.GetFileName(File.FullName))
        Next
        Return returnList
    End Function




    'Sub ListDir()
    '    'TreeView1.Nodes.Clear()

    '    Dim RootPath As String
    '    'RootPath = appPath & "profile\" & Membership.GetUser.Email & "\"
    '    RootPath = appPath & "Albums\"
    '    Dim RootPath2 As String

    '    RootPath2 = "~/Albums/"

    '    If TreeView1.Nodes.Count <= 0 Then
    '        'List My Directories
    '        Dim RootNode As TreeNode = New TreeNode("Company Events", Server.MapPath(RootPath2))
    '        TreeView1.Nodes.AddAt(0, RootNode)

    '        Dim ParentArray As String() = Directory.GetDirectories(Server.MapPath(RootPath2))


    '        For Each currentDirectory In ParentArray
    '            Dim PresetDir As String
    '            PresetDir = currentDirectory
    '            Dim DirInfo As New DirectoryInfo(PresetDir)
    '            Dim myNode As TreeNode = New TreeNode(DirInfo.Name, ConvertPhysicaltoVirtual(currentDirectory, RootPath))
    '            TreeView1.Nodes(0).ChildNodes.Add(myNode)
    '            getChild(PresetDir, myNode, RootPath)
    '        Next
    '    End If
    'End Sub
    'Sub getChild(path As String, treeviewnodeindex As TreeNode, PhsyicalRoot As String)
    '    Dim ParentArray As String() = Directory.GetDirectories(path)

    '    For Each currentDirectory In ParentArray
    '        Dim PresetDir As String
    '        PresetDir = currentDirectory
    '        Dim DirInfo As New DirectoryInfo(PresetDir)
    '        Dim myNode As TreeNode = New TreeNode(DirInfo.Name, ConvertPhysicaltoVirtual(currentDirectory, PhsyicalRoot))
    '        TreeView1.FindNode(treeviewnodeindex.ValuePath).ChildNodes.Add(myNode)
    '        getChild(PresetDir, myNode, PhsyicalRoot)
    '    Next

    'End Sub
    Function ConvertPhysicaltoVirtual(DirectoryPath As String, PhysicalRootPath As String) As String
        Dim returnstring As String = "Err"
        returnstring = DirectoryPath.Replace(PhysicalRootPath, "~/profile/" & Membership.GetUser.Email & "/")
        returnstring = returnstring.Replace("\", "/")
        returnstring = Server.MapPath(returnstring)
        Return returnstring
    End Function
    Function ConvertVirtualtoHttp(DirectoryPath As String, PhysicalRootPath As String) As String
        Dim returnstring As String = "Err"
        returnstring = DirectoryPath.Replace(PhysicalRootPath, Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath)
        returnstring = returnstring.Replace("\", "/")
        'returnstring = Server.MapPath(returnstring)
        Return returnstring
    End Function



    'Sub unused()
    '    Dim diFiles As DirectoryInfo = New DirectoryInfo("D:\Information_Management\WebSite2\albums\2014summerouting\")

    '    For Each File As FileInfo In diFiles.GetFiles("*.*")
    '        Dim NewRow1 = New TableRow()

    '        Dim IconCell As New TableCell
    '        'Dim NameCell As New TableCell
    '        'Dim ModifiedCell As New TableCell
    '        ' Dim ExtensionCell As New TableCell
    '        'Dim LengthCell As New TableCell
    '        'NewCell1.Style.Add("border-style", "solid")

    '        Dim NewIcon As New Image
    '        NewIcon.ImageUrl = ConvertVirtualtoHttp(File.FullName, appPath)
    '        NewIcon.Height = 200
    '        NewIcon.Width = 200



    '        Dim newName As New HyperLink
    '        newName.Text = File.Name
    '        newName.NavigateUrl = ConvertVirtualtoHttp(File.FullName, appPath)
    '        Dim uri As New System.Uri(File.FullName, UriKind.Absolute)
    '        'Response.Write(Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath)
    '        'Response.Write(Server.MapPath("/~"))
    '        'Response.Write(ConvertVirtualtoHttp(File.FullName, appPath))
    '        'Response.Write(Request.Url.GetLeftPart(UriPartial.Authority))


    '        ' RootPath2 & File.Name 'File.FullName

    '        Dim newModified As New Label
    '        newModified.Text = File.LastWriteTime

    '        Dim newExtension As New Label
    '        newExtension.Text = File.Extension

    '        Dim newLength As New Label
    '        newLength.Text = File.Length


    '        IconCell.Controls.Add(NewIcon)
    '        'NameCell.Controls.Add(newName)
    '        'ModifiedCell.Controls.Add(newModified)
    '        'ExtensionCell.Controls.Add(newExtension)
    '        'LengthCell.Controls.Add(newLength)




    '        NewRow1.Cells.Add(IconCell)
    '        'NewRow1.Cells.Add(NameCell)
    '        'NewRow1.Cells.Add(ModifiedCell)
    '        'NewRow1.Cells.Add(ExtensionCell)
    '        'NewRow1.Cells.Add(LengthCell)
    '        Table1.Rows.Add(NewRow1)

    '    Next
    'End Sub
End Class
